package com.leyou.trade.util;

import com.leyou.auth.utils.UserHolder;
import com.leyou.dto.UserDetails;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;


/**
 * @author 付
 */
@Data
@Component
public class CollectionNameBuilder {
    @Value("${ly.mongo.collectionNamePrefix}")
    private String namePrefix;

    public  String build(){
        //获取用户id
        UserDetails user = UserHolder.getUser();
        //健壮性判断
        if (user==null){
            //用户未登录
            return "";
        }
        //用户存在
       int index = user.getId().hashCode() % 100 ;
        return namePrefix+index;
    }
}
